/**
 * @author Vladimir Kondratyev
 */
package com.intellij.tfsSupport.commands;

import com.intellij.execution.ExecutionException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.tfsSupport.VssBundle;
import com.intellij.tfsSupport.VssConfiguration;
import com.intellij.tfsSupport.VssUtil;
import com.intellij.tfsSupport.VssConfigurable;
import org.jetbrains.annotations.NonNls;

import java.util.ArrayList;
import java.util.List;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.IOException;

public class RunExplorerCommand
{
  @NonNls private static final String ROOT_PATH = "$/";
  @NonNls private static final String _s_OPTION = "-s";
  @NonNls private static final String _p_OPTION = "-p";
  
  private Project myProject;
  private String myVssPath;

  /**
   * @param file can represent file or directory.
   */
  public RunExplorerCommand( Project project, VirtualFile file )
  {
    myProject = project;
    if( file == null){
      myVssPath = ROOT_PATH;
    }else if( !file.isDirectory() ){
      myVssPath = VssUtil.getVssPath( file.getParent(), project );
    }else if( file.isDirectory() ){
      myVssPath = VssUtil.getVssPath( file, project );
    }
  }

  public void execute()
  {
    VssConfiguration config = VssConfiguration.getInstance( myProject );
    myVssPath = config.Client().substring(0,config.Client().lastIndexOf("\\")) + "\\devenv.exe";
    try
    {
      VSSExecUtil.runProcessDoNotWaitForTermination(myVssPath);
    }
    catch( ExecutionException exc )
    {
    }
  }
}
